import { debounce } from 'lodash'

export default {
  data () {
    return {
      dataInfo: {
        blockName: null
      },
      timer: null,
      moveMouse: false
    }
  },
  created () {
    let _self = this
    addEventListener('mousedown', function (e) {
      _self.moveMouse = false
      _self.timer = new Date().getTime()
    }, false)
    addEventListener('mousemove', function (e) {
      _self.moveMouse = true
    }, false)
    addEventListener('mouseup', function (e) {
      if (e.target.closest('.block') && !e.target.closest('.block').classList.contains('dragging')) {
        if (new Date().getTime() - _self.timer < 300 && !_self.moveMouse) {
          if (e.target.closest('#canvas')) {
            const tempInfo = JSON.parse(e.target.closest('.hover-card').getAttribute('blockInfo'))
            if (tempInfo) {
              _self.showSettingModelOnce(tempInfo) // Pass Count
            }
          }
        }
      }
    }, false)
  },
  methods: {
    showSettingModelOnce: debounce(function (blockInfo) {
      this.$refs[`setting-model`].open(blockInfo)
    }, 100)
  }
}
